﻿using Inventory.Business.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.Business.DomainObjects;
using DomainObjects = Inventory.Business.DomainObjects;
using API = Inventory.Business.API;
using System.Collections.Generic;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;

namespace Inventory.Business.StateMachines.Tests
{


    /// <summary>
    ///This is a test class for PurchaseRequestTest and is intended
    ///to contain all PurchaseRequestTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PurchaseRequestTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Save
        ///</summary>
        [TestMethod()]

        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("D:\\Work\\OHD\\OHD Phase 2\\SourceCode\\Inventory.UI")]
        [UrlToTest("http://localhost:3812")]
        [Credential("ahmed", "123")]
        public void SaveTest()
        {
            System.Diagnostics.Debugger.Break();
            List<DomainObjects.Warehouse> warehouseList = LookupFacade.GetWarehouses();
            int selectedWarehouseID = warehouseList[1].ID;

            List<DomainObjects.Project> projectList = LookupFacade.GetProjects(new ProjectFiltrationOptions { WarehousesID = selectedWarehouseID, WarehouseTransactionType = null });
            int selectedProjectID = projectList[1].ID;

            API.PurchaseRequest target = new API.PurchaseRequest(); // TODO: Initialize to an appropriate value
            DomainObjects.PurchaseRequest entity = new Inventory.Business.DomainObjects.PurchaseRequest
            {
                Comment = "unit testing",
                ID = 0,
                TempWarehouseID = selectedWarehouseID,
                TempProjectID = selectedProjectID,
                DatePlaced = DateTime.Now,
                Description = "Unit testing description",
                ProjectWarehouseId = target.GetProjectWarehouseId(selectedWarehouseID, selectedProjectID),
                PurchaseRequestStatus = PurchaseRequestStatus.Open
            }; 
            target.Save(entity);
            Assert.IsTrue(entity.ID > 0);
        }
    }
}
